package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.domain.TMessage;
import com.cyzy.dto.ResponseData;
import com.cyzy.service.TMessageService;
import com.cyzy.mapper.TMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 10204
* @description 针对表【t_message(消息表)】的数据库操作Service实现
* @createDate 2024-11-24 16:16:17
*/
@Service
public class TMessageServiceImpl extends ServiceImpl<TMessageMapper, TMessage> implements TMessageService{
@Autowired
private TMessageMapper tMessageMapper;
    @Override
    public ResponseData getTMessageById(String userid) {
        //我是大帅哥
        QueryWrapper<TMessage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userid);
        queryWrapper.eq("state", 1);
        List<TMessage> tMessages = tMessageMapper.selectList(queryWrapper);

        if (tMessages.isEmpty()) {
            return ResponseData.no();  // 没有数据时返回
            //我是大帅哥
        } else {
            return new ResponseData(200, "success", tMessages, 0);  // 返回多个数据
        }
    }
}




